package main

import (
	"context"
	"fmt"
	"newtomicroc/consulconn/consul/api"
	"newtomicroc/consulconn/pb"
	"newtomicroc/rpcconn/pb/grpc-go"
)

func main() {

	//获取consul健康服务
	//初始华 consul配置
	consulConfig := api.DefaultConfig()
	//创建consul对象
	consulClient, _ := api.NewClient(consulConfig)

	//服务发现从consul发现健康服务
	servers, _, _ := consulClient.Health().Service("grpc and consul", "grpc", true, nil)
	//获取consul健康服务地址

	////《《《《《《《《《《以下事grpc调用

	//替换为 服务发现地址  连接服务
	grpcConn, _ := grpc.Dial(fmt.Sprintf("%s:%d", servers[0].Service.Address, servers[0].Service.Port), grpc.WithInsecure())
	//连接服务
	//grpcConn, _ := grpc.Dial("127.0.0.1:8800", grpc.WithInsecure())
	defer grpcConn.Close()
	//初始化gprc客户端
	grpcClinet := pb.NewHelloClient(grpcConn)

	//调用远程函数
	var person pb.Person
	person.Name = "wangtu"
	person.Age = 13

	p, _ = grpcClinet.SayHello(context.TODO(), &person)

	fmt.Println(p, err)
}
